package com.sgcc.ln.pmos.e_ln_home.activity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.ln.pmos.arouter.home.HomeArouterPath;
import com.sgcc.ln.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.ln.pmos.e_ln_home.adapter.InforDiscloFourStepAdapter;
import com.sgcc.ln.pmos.e_ln_home.bean.InformationDisclosure2Bean;
import com.sgcc.ln.pmos.e_ln_home.contract.InforDiscloFourStepContract;
import com.sgcc.ln.pmos.e_ln_home.presenter.InforDiscloFourStepPresenter;

/**
 * 信息披露 第四级菜单或者更多级菜单
 */
@Route(path = HomeArouterPath.HOME_INFORDISCLOFOURSTEP)
public class InforDiscloFourStepActivity extends MvpBaseRecycleActivity<InformationDisclosure2Bean.DataBean, InforDiscloFourStepPresenter> implements InforDiscloFourStepContract.View {

    private InformationDisclosure2Bean.DataBean mBean;
    private String mLabel;
    private InforDiscloFourStepAdapter mInforDiscloFourStepAdapter;

    @Override
    protected void receiveIntentExtras() {
        super.receiveIntentExtras();
        mBean = (InformationDisclosure2Bean.DataBean) getIntent().getSerializableExtra("data");
        mLabel = getIntent().getStringExtra("label");
    }

    @Override
    public String getTitleText() {
        return mLabel;
    }

    @Override
    protected InforDiscloFourStepPresenter createPresenter() {
        return new InforDiscloFourStepPresenter();
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        mPresenter.getData();
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        mInforDiscloFourStepAdapter = new InforDiscloFourStepAdapter(mContext);
        mInforDiscloFourStepAdapter.setOnItemClickListener(new InforDiscloFourStepAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, InformationDisclosure2Bean.DataBean bean) {
                if (bean.getChildren().size() != 0) {
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_INFORDISCLOFOURSTEP)
                            .withString("label", bean.getLabel())
                            .withSerializable("data", bean)
                            .navigation();
                } else {
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_INFOMATIONLIST)
                            .withString("label", bean.getLabel())
                            .withString("infoCode", bean.getInfoCode())
                            .navigation();
                }
            }
        });
        return mInforDiscloFourStepAdapter;
    }

    @Override
    public void getDataSuccess() {
        loadSuccess(false, mBean.getChildren());
    }

    @Override
    public void getDataFailed() {

    }
}
